package com.qst.crop.service.impl;

import com.qst.crop.dao.OrderDiscussDao;
import com.qst.crop.entity.OrderDiscuss;
import com.qst.crop.service.OrderDiscussService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 评论服务实现类
 */
@Service
public class OrderDiscussServiceImpl implements OrderDiscussService {

    private final OrderDiscussDao orderDiscussDao;

    /**
     * 通过Spring注入OrderDiscussDao
     * @param orderDiscussDao 数据访问对象
     */
    @Autowired
    public OrderDiscussServiceImpl(OrderDiscussDao orderDiscussDao) {
        this.orderDiscussDao = orderDiscussDao;
    }

    @Override
    /**
     * 实现添加新的评论
     */
    public void addOrderDiscuss(OrderDiscuss orderDiscuss) {
        orderDiscuss.setUpdateTime(LocalDateTime.now());
        orderDiscussDao.insertOrderDiscuss(orderDiscuss);
    }

    @Override
    /**
     * 实现获取所有评论列表
     */
    public List<OrderDiscuss> getOrderDiscussList(Integer id) {
        return orderDiscussDao.selectAllOrderDiscuss(id);
    }

    @Override
    /**
     * 实现根据ID获取评论
     */
    public OrderDiscuss getOrderDiscussById(Integer id) {
        return orderDiscussDao.selectOrderDiscussById(id);
    }

    @Override
    /**
     * 实现更新评论信息
     */
    public void updateOrderDiscuss(OrderDiscuss orderDiscuss) {
        orderDiscuss.setUpdateTime(LocalDateTime.now());
        orderDiscussDao.updateOrderDiscuss(orderDiscuss);
    }

    @Override
    /**
     * 实现删除评论
     */
    public void deleteOrderDiscuss(Integer id) {
        orderDiscussDao.deleteOrderDiscuss(id);
    }

    @Override
    /**
     * 实现根据用户名获取评论回复
     */
    public List<OrderDiscuss> getDiscussRepliesByUsername(String userName) {
        return orderDiscussDao.selectByUserName(userName);
    }

    @Override
    /**
     * 实现根据回复ID获取评论回复
     */
    public List<OrderDiscuss> getDiscussRepliesByReplyId(String replyId) {
        return orderDiscussDao.selectByReplyId(replyId);
    }

    @Override
    public List<OrderDiscuss> getOrderDiscussWithRepliesById(Integer replyId) {
        return orderDiscussDao.selectOrderReplyById(replyId);
    }

    @Override
    public List<OrderDiscuss> selectAllReplyDiscuss(Integer id){
        return orderDiscussDao.selectAllReplyDiscuss(id);
    }

    @Override
    public int addRepluNum(Integer discussId){
        return orderDiscussDao.addRepluNum(discussId);
    }

    @Override
    public List<Integer> userLikeList(String username){
        return orderDiscussDao.userLikeList(username);
    }

    @Override
    public int addLike(String username, Integer orderDiscussId){
        return orderDiscussDao.addLike(username,orderDiscussId);
    }
    @Override
    public int deleteLike(String username, Integer orderDiscussId){
        return orderDiscussDao.deleteLike(username,orderDiscussId);
    }
}